package com.chalk.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.chalk.dao.PictureDao;
import com.chalk.exception.ColumnNotEmptyException;
import com.chalk.model.Picture;
import com.chalk.service.PictureService;
import com.chalk.util.MpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author glq
 * @since 2020-12-19
 */

@Service
public class PictureServiceImpl extends ServiceImpl<PictureDao, Picture> implements PictureService {

    @Autowired
    MpUtil<Picture> mpUtil;
    @Override
    public int addPicture(Picture entity) {
        return baseMapper.insert(entity);
    }



    @Override
    public Page<Picture> getPictureForPage(Map<String, Object> map) throws ColumnNotEmptyException {
        EntityWrapper<Picture> wrapper=mpUtil.getWrapper();
        Page<Picture> picturePage=mpUtil.getPage(map);
        picturePage.setDescs(mpUtil.getDesc("create_time"));
        return selectPage(picturePage,wrapper);
    }


    @Override
    public Boolean savePicture(Picture picture) {
        picture.setCreateTime(LocalDateTime.now());
        picture.setPictureType(1);
        return insert(picture);
    }

    @Override
    public Boolean updatePicture(Picture picture) {
        picture.setUpdateTime(LocalDateTime.now());
        //picture.setPictureType(1);
        picture.setCensorStatus(2);
        return updateById(picture);
    }

    @Override
    public Boolean deletePicture(Integer pictureId) {
        Picture picture=new Picture();
        picture.setPictureId(pictureId);
        picture.setIsDelete(1);
        return updateById(picture);
    }
}
